package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	pb "grpc/hellogrpc"
	"log"
	"net"
)

const (
	PORT = ":50051"
)

type server struct{}

func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloResponse, error) {
	fmt.Println("grpc called")
	return &pb.HelloResponse{Reply: "Hello " + in.Name}, nil
}

func main() {
	lis, err := net.Listen("tcp", PORT)
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	s := grpc.NewServer()
	pb.RegisterHelloServiceServer(s, &server{})
	s.Serve(lis)
}
